package com.java.userservice.controller;

import com.java.common.model.Result;
import com.java.userservice.model.User;
import com.java.userservice.model.dto.UserRoleDTO;
import com.java.userservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    /**
     * 查询人员基本信息管理
     * @param user
     * @return
     */
    @PostMapping("/list")
    public Result list(@RequestBody User user) {
        return userService.list(user);
    }

    @GetMapping("/listRoleByAdminId/{id}")
    public Result listRoleByAdminId(@PathVariable Integer id) {
        return userService.listRoleByAdminId(id);
    }

    @PostMapping("/listRole")
    public Result listRole() {
        return userService.listRole();
    }

    @PostMapping("/saveRole")
    public Result saveRole(@RequestBody UserRoleDTO userRoleDTO) {
        return userService.saveRole(userRoleDTO);
    }

    @GetMapping("/get")
    public Result get(int id) {
        return userService.get(id);
    }

    /**
     * 新增人员基本信息管理
     * @param user
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody User user) {
        return userService.save(user);
    }

    /**
     * 修改人员基本信息管理
     * @param user
     * @return
     */
    @PostMapping("/modify")
    public Result modify(@RequestBody User user) {
        return userService.modify(user);
    }

    /**
     * 删除人员基本信息管理
     * @param ids
     * @return
     */
    @GetMapping("/remove")
    public Result remove(int[] ids) {
        return userService.remove(ids);
    }

    /**
     * 上传功能 具体用处待定
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result upload(@RequestPart MultipartFile file) {
        return userService.upload(file);
    }

    /**
     * 返回技师用户
     * @return
     */
    @PostMapping("/userRole")
    public Result userRole(@RequestBody User user) {
        return userService.userRole(user);
    }
}
